<template>
  <div class="Kqgl">
    <!-- 第一行 -->
    <el-row>
      <el-col class="header_col">
        <div class="header_title">考勤管理</div>
      </el-col>
    </el-row>
    <!-- 第二行 -->
    <el-row>
      <el-col>
        <div class="content_search">
          <el-form ref="form" :model="searchData" label-width="80px">
            <div>
              <el-form-item label="日期">
                <el-input
                  v-model="searchData.dateTime"
                  placeholder="请输入日期"
                  clearable
                  type="date"
                  size="small"
                ></el-input>
              </el-form-item>
            </div>
            <el-form-item label="姓名">
              <el-input
                v-model="searchData.search_Info"
                placeholder="请输入姓名"
                clearable
                size="small"
              ></el-input>
            </el-form-item>
            <el-form-item label="部门" size="small">
              <el-select
                v-model="searchData.pdept_department_id"
                placeholder="请选择部门"
                clearable
              >
                <el-option
                  v-for="v in pDeptListData"
                  :key="v.id"
                  :label="v.pdept"
                  :value="v.pdeptId"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="状态" size="small">
              <el-select
                v-model="searchData.state"
                clearable
                placeholder="请选择专业类别"
              >
                <el-option label="全部" value="0"></el-option>
                <el-option label="正常" value="1"></el-option>
                <el-option label="异常" value="2"></el-option>
              </el-select>
            </el-form-item>
            <!-- 按钮组 -->
            <div class="btn_type">
                            <el-button
                type="primary"
                icon="el-icon-zoom-in"
                @click="onSearch"
                size="mediu"
                >查询</el-button
              >
              <el-button
                type="info"
                icon="el-icon-refresh-right"
                size="mediu"
                @click="onReset"
                >重置</el-button
              >

            </div>
          </el-form>
        </div>
      </el-col>
    </el-row>
    <!-- 表格数据 -->
    <el-table :data="KqglData" style="width: 98%">
      <el-table-column prop="pname" label="姓名" width="246" align="center">
      </el-table-column>
      <el-table-column
        prop="personal.personalDept.pdept"
        label="部门"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="personal.personalJob.pjob"
        label="工种"
        align="center"
      >
      </el-table-column>
      <el-table-column prop="signin" label="签到" align="center">
        <template slot-scope="scope">{{
          scope.row.signin | formatTimer
        }}</template>
      </el-table-column>
      <el-table-column prop="signout" label="签退" align="center">
        <template slot-scope="scope">{{
          scope.row.signout | formatTimer
        }}</template>
      </el-table-column>
      <el-table-column
        prop="pstatus"
        width="246"
        label="考勤状态"
        align="center"
      >
        <template slot-scope="scope">{{
          scope.row.pstatus == 1 ? "正常" : "异常"
        }}</template>
      </el-table-column>
    </el-table>
    <!-- <hr /> -->
    <!-- 页码 -->
    <el-col :span="24">
      <div class="grid_content">
        <span class="page_total">共{{ Math.ceil(total / kqgl_limit) }}页/{{ total }}条数据</span>
        <el-pagination
          @current-change="kqgl_changePage"
          :page-size="kqgl_limit"
          layout="prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
        <span class="go_page">跳转</span>
      </div>
    </el-col>
  </div>
</template>
<script>
export default {
  data: function () {
    return {
      search_input: "",
      searchData: {
        dateTime: "",
        search_Info: "",
        pdept_department_id: "",
        state: "",
      },
      KqglData: [],
      // 下拉列表
      pDeptListData: [],
      kqgl_page: 1,
      kqgl_limit: 5,
      total: 0,
    };
  },

  methods: {
    getKqglData: function () {
      this.$axios({
        url: "/attendance/list",
        method: "post",
        data: {
          queryTime: this.searchData.dateTime,
          pname: this.searchData.search_Info,
          personalDept: {
            pdeptId: this.searchData.pdept_department_id,
          },
          pstatus: this.searchData.state,
          page: this.kqgl_page,
          limit: this.kqgl_limit,
        },
      }).then((res) => {
        // console.log(res.data);
        if (res.data.code == 0) {
          this.KqglData = res.data.data;
          this.total = res.data.total;
          this.$message.success("数据加载成功！");
        } else {
          this.$message.error("数据加载失败！");
        }
      });
    },
    // 添加
    onAddInfo: function () {},
    // 搜索
    onSearch: function () {
      this.getKqglData();
    },
    // 重置
    onReset: function () {
      this.searchData.dateTime = "";
      this.searchData.search_Info = "";
      this.searchData.pdept_department_id = "";
      this.searchData.state = "";
      this.getKqglData();
    },
    // 部门下拉列表
    pDeptList: function () {
      this.$axios({
        url: "/personal/pdept",
        method: "get",
      }).then((res) => {
        // console.log(res);
        if (res.data.code == 0) {
          this.pDeptListData = res.data.data;
        } else {
          this.$message.error("下拉框数据加载失败！");
        }
      });
    },
    // 页码
    kqgl_changePage: function (page) {
      this.kqgl_page = page;
      this.getKqglData();
    },
  },
  // 日期时间格式化过滤器
  filters: {
    formatTimer: function (time) {
      let date = new Date(time);
      let y = date.getFullYear();
      let MM = date.getMonth() + 1;
      MM = MM < 10 ? "0" + MM : MM;
      let d = date.getDate();
      d = d < 10 ? "0" + d : d;
      let h = date.getHours();
      h = h < 10 ? "0" + h : h;
      let m = date.getMinutes();
      m = m < 10 ? "0" + m : m;
      let s = date.getSeconds();
      s = s < 10 ? "0" + s : s;
      return y + "-" + MM + "-" + d + " " + h + ":" + m;
      // return h + ":" + m + ":" + s;
    },
  },
  mounted: function () {
    this.getKqglData();
    this.pDeptList();
  },
};
</script>
<style lang="less" scoped>
.Kqgl {
  width: 100%;
  height: 100%;

  .header_col {
    margin-top: 20px;
    padding-left: 30px;
  }

  .header_title {
    height: 40px;
    width: 100%;
    font-size: 24px;
    line-height: 40px;
    color: #344563;
    font-weight: bolder;
  }
  .addInformation_btn {
    width: 110px;
    height: 40px;
    background-color: #6554c0;
    color: #fff;
  }

  .content_search {
    margin-top: 20px;
    height: 130px;
    width: 100%;
    background: #ffffff;
    font-size: 16px;
    line-height: 60px;
    color: #344563;
    font-weight: bolder;
    .el-form {
      width: 100%;
      height: 50px;
      line-height: 50px;
      min-width: 1300px;
    }
    .el-form-item {
      width: 300px;
      height: 40px;
      display: inline-block;
    }
    // 输入框
    .el-input {
      width: 200px;
    }

    .btn_type {
      width: 240px;
      height: 41px;
      margin-left: 100px;
      line-height: 41px;
      display: inline-block;
    }

    .el-button {
      padding: 0;
      text-align: center;
      width: 80px;
      height: 40px;
      line-height: 40px;
      margin-left: 30px;
    }
    .el-icon-search {
      font-size: 28px;
    }
    .search_btn {
      background: #64c8bc;
      border: 1px solid #64c8bc;
    }
    .el-icon-refresh-right {
      font-size: 28px;
    }
    .reset_btn {
      background: #61a4e4;
      border: 1px solid #61a4e4;
    }
    .del_btn {
      font-size: 14px;
      color: #ffc5c5;
      background: #fef3f3;
      border-color: #fef3f3;
    }

    .edit_btn {
      font-size: 14px;
      color: #5fa4e2;
      font-weight: bolder;
      background: #eef6fc;
      border-color: #eef6fc;
    }
  }
  // 表格
  .el-table {
    border: none;
    margin-top: 20px;
    margin-left: 20px;
    border: none;
    // font-size: 18px;
    // border-bottom: 1px solid #aaa;
  }
  // 底部页码
  .grid_content {
    // background: #61a4e4;
    line-height: 40px;
    position: relative;

    .el-pagination {
      border-radius: 10px;
      position: absolute;
      top: 25px;
      right: 90px;
      color: #a1a1a1;
    }
    .go_page {
      font-size: 14px;
      position: absolute;
      top: 20px;
      right: 50px;
      color: #7161c5;
      &:hover {
        cursor: pointer;
      }
    }
    .page_total {
      font-size: 14px;
      position: absolute;
      top: 20px;
      right: 620px;
      color: #a8afbc;
    }
  }
}
</style>